// 加载FORM表单扩展
layui.use(['form','laydate'], function(){
	var form = layui.form()
	,layer = layui.layer,
	laydate = layui.laydate;
	
	//自定义验证规则
	form.verify({
		order_name: function(value){
		  if(value.length < 1){
			return '请输入订单名称';
		  }
		}
	});

	//监听提交
	form.on('submit(submit)', function(data){
		var URL = '/AdOrder/add';
		
		var formData = data.field;
		var postData = {};
		postData['order_name']			=   formData.order_name;
		postData['sale_mode']           =   formData.sale_mode;
		postData['start_time']          =   formData.startTime;
		postData['end_time']            =   formData.endTime;
		postData['contract_number']     =   formData.contract_number;
		postData['sale_people']         =   formData.sale_people;
		postData['delivery_people']     =   formData.delivery_people;
		postData['cid']                 =   formData.cid;
		postData['remark']              =   formData.remark;
        postData['amount']              =   formData.amount;
		postData['change']              =   formData.change;

		if( typeof formData.oid != 'undefined' ) {
			postData['id'] = formData.oid;
			URL = '/AdOrder/edit';
		}

		$.ajax({
			type:"POST",
			url:URL,
			dataType:"json",
			data:postData,
			success: function(data){
			  if(data.status == 'success') {
				  PopModel.refreshParentFrame();
			  } else {
				layer.msg(data.msg, {icon: 5, shift: 6}, function(){});
			  }
			return false;
			}
		});

		return false;
	});
	// 刷新表单
	form.render();
});
